#  @brief 4G DTU 编译工程文件
#  @version 1.0
#  @date 2018-2-28
#  @author 宋炜
## 512 版
QL_SDK_PATH = /root/EC20CEFAGR06A02M4G_OCPU_BETA0424_SDK/ql-ol-sdk/ql-ol-extsdk
# 256 版本
#QL_SDK_PATH = /root/ql-ol-sdk/ql-ol-extsdk

#SDKTARGETSYSROOT = /home/galaxy/EC20CEFAGR06A04M4G_OCPU_SDK/ql-ol-sdk/ql-ol-crosstool/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr
# 512 版
SDKTARGETSYSROOT = /root/EC20CEFAGR06A02M4G_OCPU_BETA0424_SDK/ql-ol-sdk/ql-ol-crosstool/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr
# 256 版本
#SDKTARGETSYSROOT = /root/ql-ol-sdk/ql-ol-crosstool/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr

STD_LIB= $(SDKTARGETSYSROOT)/lib/libdsi_netctrl.so     \
         $(SDKTARGETSYSROOT)/lib/libdsutils.so         \
         $(SDKTARGETSYSROOT)/lib/libqmiservices.so     \
         $(SDKTARGETSYSROOT)/lib/libqmi_cci.so         \
         $(SDKTARGETSYSROOT)/lib/libqmi_common_so.so   \
         $(SDKTARGETSYSROOT)/lib/libqmi.so             \
         $(SDKTARGETSYSROOT)/lib/libmcm.so             \

QL_EXP_LDLIBS=${QL_SDK_PATH}/lib/libql_peripheral.a -lql_common_api ${QL_SDK_PATH}/lib/libquecIO.a -lpthread # -lql_at 

DEFINES = -D__DEBUG__ -DTIXML_USE_STL

INCLUDES = -I$(QL_TOOLS_PATH)/mdm9607/usr/include -I${SDKTARGETSYSROOT}/include -I${SDKTARGETSYSROOT}/include/qmi -I${SDKTARGETSYSROOT}/include/qmi-framework -Iinclude -I${QL_SDK_PATH}/include -I${QL_SDK_PATH}/include/mqtt

CPPFLAGS = $(DEFINES) $(INCLUDES)
TEST_CPPFLAGS = $(DEFINES) $(TEST_INCLUDES)

LIBS = ${STD_LIB} ${QL_EXP_LDLIBS} -liconv -lssl -lz -ltinyxml -lcurl -luv -lcrypto -pthread -lrt -lstdc++
# -lpaho-mqttpp3 
#
LDFLAGS = -O1 -s -L${SDKTARGETSYSROOT}/lib -L$(QL_SDK_PATH)/lib

CFLAGS = -std=c++1y -Wall -O1 -s
DBG_CFLAGS = -std=c++1y -Wall -g
TEST_CFLAGS = -std=c++1y -Wall -g

TEST_LD = gcc
TEST_CC = gcc

# 编译UBUNTU 版本的参数和变量
UBUNTU_CC = gcc
UBUNTU_LD = gcc
UBUNTU_INC = -Iinclude -Isrc/quectel
UBUNTU_LIBS = -liconv -lssl -lz -ltinyxml -lcurl -luv -lcrypto -pthread -lstdc++
UBUNTU_CFLAGS = -g -std=c++14 -Wall
UBUNTU_CPPFLAGS = $(UBUNTU_INC) 
UBUNTU_LDFLAGS = ${UBUNTU_LIBS} -g 

# DTU程序
DTUOBJS = main.o src/at.o src/sms.o src/smsio.o src/dial.o src/cconffile.o src/crypto.o src/dtu.o     \
src/filterio.o src/http.o src/leds.o src/memio.o src/misc.o src/reporter.o src/rfc2217.o src/rudp.o   \
src/serial.o src/serialio.o src/sys_var.o src/tcp.o src/timer.o src/udp.o src/uv_tcp_c.o              \
src/sdp.o src/uv_udp_c.o src/zipio.o src/uvlper.o src/resolver.o src/base64.o src/mqtt.o              \
src/gps.o src/modbus_setting.o src/modbus.o src/crc.o src/dwld.o src/url.o  src/devM.o

# ubuntu 下编译的可以在ubuntu 电脑上运行的版本。这个版本使用了虚拟的EC20设备SDK库，方便调试 
UBUNTU_OBJS = $(DTUOBJS) src/quectel/ql_mcm_sms.o src/quectel/ql_acdb.o src/quectel/ql_adc.o      	      	 \
src/quectel/ql_at.o src/quectel/ql_audio.o src/quectel/ql_dev.o src/quectel/ql_eint.o src/quectel/ql_gpio.o  \
src/quectel/ql_i2c.o src/quectel/ql_mcm_gps.o src/quectel/ql_nand.o src/quectel/ql_network.o                 \
src/quectel/ql_nslookup.o src/quectel/ql_nw.o src/quectel/ql_sim.o src/quectel/ql_uart.o 					 \
src/quectel/ql_wwan_v2.o src/quectel/ql_mcm_nw.o src/quectel/ql_sgmii.o
# 编译发布版
all : dtu
	
# 编译调试版
debug : dbg_dtu

# 编译820
router: ROUTER
	
# 编译电脑调试版
ubuntu: $(UBUNTU_OBJS)
	$(UBUNTU_LD) $(UBUNTU_LDFLAGS) $(UBUNTU_OBJS) $(UBUNTU_LIBS) -o bin/debug/ubuntu_dtu
# 编译测试
test : at_test

dtu: $(DTUOBJS)
	$(LINK.o) ${LDFLAGS} $(DTUOBJS) $(CFLAGS) -o bin/release/dtu $(LIBS)
	cp bin/release/dtu /media/sf_E_DRIVE/ftpfiles

dbg_dtu: $(DTUOBJS)
	$(LINK.o) ${DBG_LDFLAGS} $(DTUOBJS) $(DBG_CFLAGS) -o bin/debug/dtu $(LIBS)
	
ROUTER: $(DTUOBJS)
	$(LINK.o) ${LDFLAGS} $(DTUOBJS) $(CFLAGS) -o bin/release/dtu820 $(LIBS)
	cp bin/release/dtu820 /media/sf_E_DRIVE/ftpfiles

$(DTUOBJS):%.o: %.cpp
	$(COMPILE.c) ${CPPFLAGS} $(CFLAGS) $< -o $@

##################################################################################################
# 编译在ubuntu下运行的目标文件
#$(UBUNTU_OBJS):%.o: %.cpp
#	$(UBUNTU_CC) $(DEFINES) $(UBUNTU_CPPFLAGS) $(UBUNTU_CFLAGS) -c $< -o $@
##################################################################################################

# 清理
.PHONY:clean
clean :
	rm -f bin/release/*
	rm -f bin/debug/*
	rm -f bin/test/*
	rm -f lib/release/*.o
	rm -f lib/debug/*.o
	rm -f lib/test/*.o
	rm -f src/*.o
	rm -f src/rudp/*.o
	rm -f src/quectel/*.o
	rm -f *.o
